﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Excel = Microsoft.Office.Interop.Excel;
using Common = PCS.Common;

namespace PCS.Util
{
    class ExcelUtil
    {
        public Excel.Application app;

        //public int No { set; }
        //public string OriginalName { set; }
        //public string ResourceName { set; }
        //public DateTime StartDate { set; }
        //public DateTime FinishDate { set; }
        //public decimal Effort { set; }


        //insert row in excel.
        public void Insert(int i, string original_name, string mon, bool flgOneResource, string resource_name,System.DateTime start_date, System.DateTime finish_date, decimal effort)
        {
            Excel.Worksheet ws;
            Excel.Range range;

            //Revision 2:
            string resource_name_for_taskname;

            ws =app.ActiveSheet;
            range = ws.Rows[i];
            range.Select();
            app.Selection.Copy();

            ws.Rows[i + 1].Select();
            app.Selection.Insert(Excel.XlDirection.xlDown);
            app.CutCopyMode = Excel.XlCutCopyMode.xlCopy;
            ws.Cells[i+1,Common.Const.RESOURCE_NAME_COLUMN].value = resource_name;
            if (!string.IsNullOrEmpty(mon))
                mon = "-" + mon;
            else
                mon = "";

            if (!flgOneResource)
                resource_name_for_taskname = "-" + resource_name;
            else
                resource_name_for_taskname = "";
            ws.Cells[i + 1, Common.Const.TASK_NAME_COLUMN].value = original_name + mon + resource_name_for_taskname;
            ws.Cells[i+1,Common.Const.TASK_NAME_COLUMN].Interior.PatternColorIndex = Excel.XlPattern.xlPatternAutomatic;
            ws.Cells[i+1,Common.Const.TASK_NAME_COLUMN].Interior.Color = 5287936;

            ws.Cells[i + 1, Common.Const.START_DATE_COLUMN].value = start_date.ToShortDateString();
            ws.Cells[i + 1, Common.Const.FINISH_DATE_COLUMN].value = finish_date.ToShortDateString();

            ws.Cells[i + 1, Common.Const.WORK_COLUMN].value = effort;
             
        }

    }
}
